<template>
	<view class="wrap">
		<!-- <view class="top"></view> -->
		<view class="content">
			<view class="title">设置登录密码!</view>
			<u-form :model="model" :rules="rules" ref="uForm">
				<u-form-item label="密码" prop="pwd">
					<u-input style="height: 80rpx;overflow: hidden;" :password-icon="true" :border="false" type="password" v-model="model.pwd" placeholder="请输入密码">
					</u-input>
				</u-form-item>
				<u-form-item label="确认密码" label-width="150" prop="repwd">
					<u-input style="height: 80rpx;overflow: hidden;" :border="false" type="password" v-model="model.repwd" placeholder="请确认密码"></u-input>
				</u-form-item>
			</u-form>
			<u-button @click="submit" class="getCaptcha" style="margin-top: 40rpx;">确认</u-button>
		</view>
	</view>
</template>

<script>
	import {userupdate} from '@/common/api/user.js'
	import {
			setUser,
			getUser
		} from '@/common/entity/user.js'
	export default {
		data() {
			let that = this
			return {
				model:{
					pwd: '',
					repwd: ''
				},
				rules: {
					pwd: [{
							required: true,
							message: '请输入密码',
							trigger: ['change', 'blur'],
						},
						{
							// 正则不能含有两边的引号
							pattern: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]+\S{5,12}$/,
							message: '需同时含有字母和数字，长度在6-12之间',
							trigger: ['change', 'blur'],
						}
					],
					repwd: [{
							required: true,
							message: '请重新输入密码',
							trigger: ['change', 'blur'],
						},
						{
							validator: (rule, value, callback) => {
								return value === that.model.pwd;
							},
							message: '两次输入的密码不相等',
							trigger: ['change', 'blur'],
						}
					],
				},
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		computed: {
			inputStyle() {
				let style = {};
				if (this.tel) {
					style.color = "#fff";
					style.backgroundColor = this.$u.color['warning'];
				}
				return style;
			}
		},
		methods: {
			submit() {
				// this.$u.toast("登录成功！")
				// console.log(this.model)
				let user = getUser()
				let updateObj = {
					id:user.id,
					userpwd:this.model.pwd
				}
				userupdate(updateObj).then(res=>{
					if(res[1].data.result){
						this.$u.toast("登录成功！")
						setUser(res[1].data.data)
						setTimeout(()=>{
							this.$u.route({
								type: 'switchTab',
								url: '/pages/index/index'
							})
						},500)
					}
				})

				
			},
			toLogin() {
				uni.navigateTo({
					url: '../login/login'
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	.wrap {
		font-size: 28rpx;
		height: 100vh;
		padding: 80rpx 60rpx;

		.content {
			width: 600rpx;

			.title {
				text-align: left;
				font-size: 60rpx;
				font-weight: 500;
				margin-bottom: 100rpx;
			}

			input {
				text-align: left;
				margin-bottom: 20rpx;
				padding: 6rpx 16rpx;
				box-sizing: border-box;
				border: 2rpx solid #eee;
				border-radius: 4px;
				height: 80rpx;
				background-color: #fff;
			}

			.tips {
				color: $u-type-info;
				margin-bottom: 60rpx;
				margin-top: 8rpx;
			}

			.getCaptcha {
				background-color: rgb(253, 243, 208);
				color: $u-tips-color;
				border: none;
				font-size: 30rpx;
				padding: 12rpx 0;

				&::after {
					border: none;
				}
			}

			.alternative {
				color: $u-tips-color;
				display: flex;
				justify-content: space-between;
				margin-top: 30rpx;
			}
		}

		.buttom {
			.loginType {
				display: flex;
				padding: 350rpx 150rpx 150rpx 150rpx;
				justify-content: space-between;

				.item {
					display: flex;
					flex-direction: column;
					align-items: center;
					color: $u-content-color;
					font-size: 28rpx;
				}
			}

			.hint {
				padding: 20rpx 40rpx;
				font-size: 20rpx;
				color: $u-tips-color;

				.link {
					color: $u-type-warning;
				}
			}
		}
	}
</style>
